package com.sky.mapper;

import com.sky.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * @author moningxi
 */
@Mapper
public interface UserMapper {
    /**
     * 更据openId查询用户
     */
    @Select("select * from user where openid=#{openId}")
    User getByOpenId(String openId);

    /**
     * 新增用户
     */
    void save(User user);

    /**
     * 更据id查询用户
     */
    @Select("select * from user where id=#{userId}")
    User getById(Long userId);

    /**
     * 每日新增用户统计
     */
    @Select("SELECT DATE(create_time) as date,COUNT(1) as sum FROM user where create_time>=#{beginTime} and create_time <=#{endTime} GROUP BY date")
    List<Map<String, Object>> newAddSum(LocalDateTime beginTime, LocalDateTime endTime);

    /**
     * 每日总人数
     */
    @Select("select count(1) from user where create_time<=#{beginTime}")
    Long totalSum(LocalDateTime beginTime);
}
